﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SmartBlast
{
    public partial class frmLoginAdmin : Form
    {
        private static string TABLE_NAME = "Employees";
        private DataBase_BUS databaseBUS;
        private static string[] FIELD_NAMES = new string[] { "Username", "Password", "Permission"};
        private Main main;

        public frmLoginAdmin(Main main)
        {
            InitializeComponent();
            databaseBUS = DataBase_BUS.getInstance();
            this.main = main;
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUser.Text == "" || txtPass.Text == "")
            {
                MessageBox.Show("\nMissing Fields!", ":(", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            string[] fields = { "'" + txtUser.Text + "'", "'" + txtPass.Text + "'","1" };

            DataTable loginDataTable = databaseBUS.selectRecrordFromTable(TABLE_NAME, FIELD_NAMES, fields);

            if (loginDataTable.Rows.Count == 0)
            {
                MessageBox.Show("\nInvalid Login", ":(", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                goToEmployeesWindow();
            }
        }

        private void goToEmployeesWindow()
        {
            frmEmployees frmEmp = new frmEmployees(main);
            frmEmp.Show();
            this.Hide();
        }

        private void txtBack_Click(object sender, EventArgs e)
        {
            main.Show();
            this.Hide();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            goToEmployeesWindow();
        }

        private void frmLoginAdmin_Load(object sender, EventArgs e)
        {
            this.CenterToScreen();
        }

    }
}
